package com.ourteam.product.model.dao.impl;

import com.ourteam.product.model.dao.IProductModelServiceFeatureRelateDAO;
import com.ourteam.product.model.dao.ProductModelServiceFeatureRelate;
import com.ourteam.product.model.dao.ProductModelServiceFeatureRelateDAOQueryBean;

import net.dao.AbstractSpringDAO;
import net.dao.DataAccessObjectHelper;

import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.lang.StringUtils;

import org.springframework.jdbc.core.RowMapper;

import java.sql.ResultSet;
import java.sql.SQLException;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;


/**
 * Template Name : DAO服务对象
 * Template Version : 1
 * Template Last Modfiy Date : Fri Nov 17 11:00:11 IRKT 2017
 * Auto Generate Date : 2017-11-17 11:01:20
  * Warning ! This file will be overwrite when regenerate !
  *
 */
public class AbstractProductModelServiceFeatureRelateDAOJdbcImpl
    extends AbstractSpringDAO implements IProductModelServiceFeatureRelateDAO {
    public static final String[] ENTITY_FIELDS = new String[] {
            Id, ServiceId, Status, Remarks, FeatureVersionRelateId, ServiceName,
            ServiceCanTest
        };
    public static final String[] ENTITY_PROPERTIES = new String[] {
            _DataObjectProperty.Id, _DataObjectProperty.ServiceId,
            _DataObjectProperty.Status, _DataObjectProperty.Remarks,
            _DataObjectProperty.FeatureVersionRelateId,
            _DataObjectProperty.ServiceName, _DataObjectProperty.ServiceCanTest
        };
    public static final String[] ENTITY_PK_FIELDS = new String[] { Id };
    public static final String[] ENTITY_AUTO_GEN_PK_FIELDS = new String[] { Id };
    public static final String[] ENTITY_UNIQUE_FIELDS = new String[] {  };
    private static String relatedJoinSQL = null;
    private static String basicFilterSQL = null;
    private DataAccessObjectHelper<ProductModelServiceFeatureRelate, ProductModelServiceFeatureRelateDAOQueryBean> daoHelper;

    public AbstractProductModelServiceFeatureRelateDAOJdbcImpl() {
        super();
        daoHelper = new DataAccessObjectHelper<ProductModelServiceFeatureRelate, ProductModelServiceFeatureRelateDAOQueryBean>(this);
    }

    protected String getEntityName() {
        return EntityName;
    }

    protected String[] getEntityFields() {
        return ENTITY_FIELDS;
    }

    protected String[] getEntityProperties() {
        return ENTITY_PROPERTIES;
    }

    protected String[] getEntityPKFields() {
        return ENTITY_PK_FIELDS;
    }

    protected String[] getEntityAutoGenPKFields() {
        return ENTITY_AUTO_GEN_PK_FIELDS;
    }

    protected String[] getEntityUniqueFields() {
        return ENTITY_UNIQUE_FIELDS;
    }

    protected String getBaiscQueryFilter() {
        if (basicFilterSQL == null) {
            StringBuffer basicFilterSQLbuffer = new StringBuffer();

            basicFilterSQL = basicFilterSQLbuffer.toString();
        }

        return basicFilterSQL;
    }

    protected String getRelatedJoinSQL() {
        if (relatedJoinSQL == null) {
            StringBuffer relatedJoinSQLBuffer = new StringBuffer();

            relatedJoinSQLBuffer.append(" LEFT JOIN ")
                                .append(com.ourteam.product.model.dao.IProductModelServiceDAO.EntityName)
                                .append(" PRODUCT_MODEL_SERVICE ");

            relatedJoinSQLBuffer.append(" ON ( ");

            relatedJoinSQLBuffer.append(StringUtils.replace(
                    com.ourteam.product.model.dao.IProductModelServiceDAO.Id,
                    com.ourteam.product.model.dao.IProductModelServiceDAO.EntityName +
                    ".", "PRODUCT_MODEL_SERVICE."));
            relatedJoinSQLBuffer.append(" = ").append(ServiceId);

            relatedJoinSQLBuffer.append(" ) ");

            relatedJoinSQL = relatedJoinSQLBuffer.toString();
        }

        return relatedJoinSQL;
    }

    /**
         * Check Data Unique
         * @param aProductModelServiceFeatureRelate
         * @throws Exception
         */
    public boolean checkIsUnique(
        ProductModelServiceFeatureRelate aProductModelServiceFeatureRelate)
        throws Exception {
        if (aProductModelServiceFeatureRelate == null) {
            return true;
        }

        List valueList = new ArrayList();

        List pkValueList = new ArrayList();

        pkValueList.add(aProductModelServiceFeatureRelate.getId());

        return isUnique(valueList.toArray(new Object[valueList.size()]),
            pkValueList.toArray(new Object[pkValueList.size()]));
    }

    /**
     * Insert Data
     * @param aProductModelServiceFeatureRelate
     * @throws Exception
     */
    public void insert(
        ProductModelServiceFeatureRelate aProductModelServiceFeatureRelate)
        throws Exception {
        super.doInsert(aProductModelServiceFeatureRelate);
    }

    /**
         * Batch Insert Datas
         * @param aProductModelServiceFeatureRelate
         * @throws Exception
         */
    public void batchInsert(
        ProductModelServiceFeatureRelate[] aProductModelServiceFeatureRelates)
        throws Exception {
        super.doBatchInsert(aProductModelServiceFeatureRelates);
    }

    /**
         * Delete Data
         * @param  final long id         *
         * @throws Exception
         */
    public void delete(final long id) throws Exception {
        super.doDeleteById(new Object[] { new Long(id) });
    }

    /**
     * Delete Datas
     * @param queryBean
     * @throws Exception
     */
    public void delete(ProductModelServiceFeatureRelateDAOQueryBean queryBean)
        throws Exception {
        super.doDeleteByQuery(queryBean);
    }

    public void delete(
        ProductModelServiceFeatureRelate aProductModelServiceFeatureRelate)
        throws Exception {
        delete(aProductModelServiceFeatureRelate.getId());
    }

    /**
     * Update Data Selective
     * @param aProductModelServiceFeatureRelate
     * @throws Exception
     */
    public void update(
        ProductModelServiceFeatureRelate aProductModelServiceFeatureRelate)
        throws Exception {
        if (aProductModelServiceFeatureRelate.getId() == 0) {
            throw new Exception(
                "Can not update object data whith out primary key value");
        }

        super.doUpdate(aProductModelServiceFeatureRelate);

        ProductModelServiceFeatureRelate tempObj = findById(aProductModelServiceFeatureRelate.getId());

        if (tempObj != null) {
            PropertyUtils.copyProperties(aProductModelServiceFeatureRelate,
                tempObj);
        }
    }

    /**
     * Batch Update Datas
     * @param aProductModelServiceFeatureRelates[]
     * @throws Exception
     */
    public void batchUpdate(
        ProductModelServiceFeatureRelate[] aProductModelServiceFeatureRelates)
        throws Exception {
        super.doBatchUpdate(aProductModelServiceFeatureRelates);
    }

    /**
         * Update Data By Condictions
         * @param aProductModelServiceFeatureRelate
         * @param aValueCriteria
         * @param aTransaction
         * @throws Exception
         */
    public void update(
        ProductModelServiceFeatureRelate aProductModelServiceFeatureRelate,
        ProductModelServiceFeatureRelateDAOQueryBean aQueryBean)
        throws Exception {
        super.doUpdateByQuery(aProductModelServiceFeatureRelate, aQueryBean);
    }

    /**
     * Update Data By Condictions
     * @param aQueryBean
     * @throws Exception
     */
    public void update(ProductModelServiceFeatureRelateDAOQueryBean aQueryBean)
        throws Exception {
        super.doUpdateByQuery(aQueryBean);
    }

    protected void checkNullValue(
        ProductModelServiceFeatureRelate aProductModelServiceFeatureRelate)
        throws Exception {
        if (aProductModelServiceFeatureRelate.getStatus() == null) {
            throw new Exception(
                "The ProductModelServiceFeatureRelate.status value is not allow NULL");
        }

        if (aProductModelServiceFeatureRelate.getRemarks() == null) {
            throw new Exception(
                "The ProductModelServiceFeatureRelate.remarks value is not allow NULL");
        }

        if (aProductModelServiceFeatureRelate.getFeatureName() == null) {
            throw new Exception(
                "The ProductModelServiceFeatureRelate.featureName value is not allow NULL");
        }

        if (aProductModelServiceFeatureRelate.getKeyFeature() == null) {
            throw new Exception(
                "The ProductModelServiceFeatureRelate.keyFeature value is not allow NULL");
        }

        if (aProductModelServiceFeatureRelate.getFeatureCanTest() == null) {
            throw new Exception(
                "The ProductModelServiceFeatureRelate.featureCanTest value is not allow NULL");
        }

        if (aProductModelServiceFeatureRelate.getServiceName() == null) {
            throw new Exception(
                "The ProductModelServiceFeatureRelate.serviceName value is not allow NULL");
        }

        if (aProductModelServiceFeatureRelate.getServiceCanTest() == null) {
            throw new Exception(
                "The ProductModelServiceFeatureRelate.serviceCanTest value is not allow NULL");
        }

        if (aProductModelServiceFeatureRelate.getProductName() == null) {
            throw new Exception(
                "The ProductModelServiceFeatureRelate.productName value is not allow NULL");
        }

        if (aProductModelServiceFeatureRelate.getProductVersion() == null) {
            throw new Exception(
                "The ProductModelServiceFeatureRelate.productVersion value is not allow NULL");
        }
    }

    /**
     * Get Data By ID
     * @param  final long id         * @return  ${businessObject.name}
     * @throws Exception
     */
    public ProductModelServiceFeatureRelate findById(final long id)
        throws Exception {
        ProductModelServiceFeatureRelateDAOQueryBean queryBean = new ProductModelServiceFeatureRelateDAOQueryBean();

        ProductModelServiceFeatureRelateDAOQueryBean.Criteria criteria = queryBean.createCriteria();

        criteria.andIdEqualTo(id);

        //queryBean.setDistinct(true);
        ProductModelServiceFeatureRelate[] ProductModelServiceFeatureRelates = query(queryBean);

        if (ProductModelServiceFeatureRelates.length == 0) {
            return null;
        } else {
            return ProductModelServiceFeatureRelates[0];
        }
    }

    /**
         * Query Data
         * @param queryBean
         * @return ProductModelServiceFeatureRelate[]
         * @throws Exception
         */
    public ProductModelServiceFeatureRelate[] query(
        ProductModelServiceFeatureRelateDAOQueryBean queryBean)
        throws Exception {
        List result = super.doQuery(queryBean,
                new JdbcProductModelServiceFeatureRelateRowMapper());

        return (ProductModelServiceFeatureRelate[]) result.toArray(new ProductModelServiceFeatureRelate[result.size()]);
    }

    /**
     * Query ${businessObject.name} Selective
     * @param queryBean
     * @return Map[]
     * @model
     * @throws Exception
     */
    public Map<String, Object>[] querySelective(
        ProductModelServiceFeatureRelateDAOQueryBean queryBean)
        throws Exception {
        if (queryBean.getSelectProperties().isEmpty()) {
            queryBean.addAllSelectProperties();
        }

        return super.doQuerySelective(queryBean);
    }

    /**
     * Query Data Count
     * @param queryBean
     * @return int
     * @throws Exception
     */
    public int queryCount(
        ProductModelServiceFeatureRelateDAOQueryBean queryBean)
        throws Exception {
        return super.doQueryCount(queryBean);
    }

    public void synchronize(
        ProductModelServiceFeatureRelate[] aProductModelServiceFeatureRelates,
        ProductModelServiceFeatureRelateDAOQueryBean queryBean)
        throws Exception {
        daoHelper.synchronize(aProductModelServiceFeatureRelates, queryBean);
    }

    public void synchronize(
        ProductModelServiceFeatureRelate[] aProductModelServiceFeatureRelates,
        ProductModelServiceFeatureRelateDAOQueryBean queryBean,
        net.dao.IDataAccessInterface.ISynchronizeCallback<ProductModelServiceFeatureRelate> callBack)
        throws Exception {
        daoHelper.synchronize(aProductModelServiceFeatureRelates, queryBean,
            callBack);
    }

    public static class JdbcProductModelServiceFeatureRelateRowMapper
        implements RowMapper<ProductModelServiceFeatureRelate> {
        public ProductModelServiceFeatureRelate mapRow(ResultSet resultSet,
            int arg1) throws SQLException {
            ProductModelServiceFeatureRelate object = new ProductModelServiceFeatureRelate();

            int columnIndex = 1;

            int __dataType;

            try {
                Object id = null;

                id = resultSet.getObject(columnIndex++);

                object.setIdNull(resultSet.getBoolean(columnIndex++));

                if (id != null) {
                    setBeanValue(object, _DataObjectProperty.Id, id);
                }

                Object serviceId = null;

                serviceId = resultSet.getObject(columnIndex++);

                object.setServiceIdNull(resultSet.getBoolean(columnIndex++));

                if (serviceId != null) {
                    setBeanValue(object, _DataObjectProperty.ServiceId,
                        serviceId);
                }

                Object status = null;

                status = resultSet.getObject(columnIndex++);

                object.setStatusNull(resultSet.getBoolean(columnIndex++));

                if (status != null) {
                    setBeanValue(object, _DataObjectProperty.Status, status);
                }

                Object remarks = null;

                remarks = resultSet.getObject(columnIndex++);

                object.setRemarksNull(resultSet.getBoolean(columnIndex++));

                if (remarks != null) {
                    setBeanValue(object, _DataObjectProperty.Remarks, remarks);
                }

                Object featureVersionRelateId = null;

                featureVersionRelateId = resultSet.getObject(columnIndex++);

                object.setFeatureVersionRelateIdNull(resultSet.getBoolean(
                        columnIndex++));

                if (featureVersionRelateId != null) {
                    setBeanValue(object,
                        _DataObjectProperty.FeatureVersionRelateId,
                        featureVersionRelateId);
                }

                Object serviceName = null;

                serviceName = resultSet.getObject(columnIndex++);

                object.setServiceNameNull(resultSet.getBoolean(columnIndex++));

                if (serviceName != null) {
                    setBeanValue(object, _DataObjectProperty.ServiceName,
                        serviceName);
                }

                Object serviceCanTest = null;

                serviceCanTest = resultSet.getObject(columnIndex++);

                object.setServiceCanTestNull(resultSet.getBoolean(columnIndex++));

                if (serviceCanTest != null) {
                    setBeanValue(object, _DataObjectProperty.ServiceCanTest,
                        serviceCanTest);
                }

                return object;
            } catch (Exception e) {
                throw new SQLException(e.getMessage());
            }
        }
    }
}
